import App from './App'

import Vue from 'vue'
import './uni.promisify.adaptor'
import uView from '@/uni_modules/uview-ui'

import store from './store'
import data from './data' //测试用数据

// const axjs = type=>{
// 	//模拟异步请求数据
// 	return new Promise(resolve=>{
// 		setTimeout(()=>{
// 			resolve(data[type]);
// 			if(data[type] && data[type]['code']){
// 				if(data[type]['code']==1){
// 					console.log('dd',data[type]);
					
// 				}else if(data[type]['code']==0){
// 					console.log('ff',data[type]);
// 				}
// 			}
			
// 		}, 1000)
// 	})
// }

const axjs = (type, params = {}) => {
  return new Promise((resolve, reject) => {
    uni.request({
      url: `http://192.168.1.90:8013/index.php/baseinformation/Fauiltfile/${type}`, // 替换为你的真实API地址
      method: 'POST', // 或 'GET' 根据你的API要求
      data: params,
      header: {
        'Content-Type': 'application/json'
        //'Authorization': 'Bearer ' + uni.getStorageSync('token') // 如果需要token
      },
      success: (res) => {
        if (res.statusCode === 200) {
          if (res.data && res.data.code === 1) {
            console.log('请求成功', res.data);
            resolve(res.data);
          } else {
            console.log('业务逻辑错误', res.data);
            reject(res.data);
          }
        } else {
          reject(new Error(`请求失败，状态码：${res.statusCode}`));
        }
      },
      fail: (err) => {
        console.error('请求失败', err);
        reject(err);
      }
    });
  });
};

const msg = (title, duration=1500, mask=false, icon='none')=>{
	//统一提示方便全局修改
	if(Boolean(title) === false){
		return;
	}
	uni.showToast({
		title,
		duration,
		mask,
		icon
	});
}
const prePage = ()=>{
	let pages = getCurrentPages();
	let prePage = pages[pages.length - 2];
	// #ifdef H5
	return prePage;
	// #endif
	return prePage.$vm;
}

Vue.use(uView)
Vue.prototype.$api = {msg, axjs, prePage};
Vue.prototype.$store = store;
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
  ...App
})
app.$mount()